package algorithm;

/**
 * create by yongli on 2020-08-10 16:47
 */

public class BulbSort {
    public static void main(String[] args) {
        int[] nums ={13,3,23,1,89,2,34};
        int[] nums2 =mothod1(nums);
        for(int i = 0;i<nums2.length;i++){
            System.out.println(nums2[i]);
        }

    }

    public static int[] sort(int[] nums) {
        //
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            int min = nums[i];
            for (int j = i ; j <= i; j++) {
                // 交换
                if (min > nums[j]) {
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                    min = nums[i];
                }
            }
        }
        return nums;
    }
    public static int[] mothod1(int[]arr){
        if(arr==null||arr.length<2){
            return arr;
        }
        else{

                for(int i=0;i<arr.length-1;i++){
                    if(arr[i]>arr[i+1]){
                        swap(arr,i,i+1);
                    }

                }


        }


        return  arr;
    }
    public static void swap (int[]arr,int i,int j){
        int temp;
        temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;

    }
}
